<?

function comment_system($tableName, $self, $key) {
	echo "<h3>Komentarze</h3>\n";
	require('globals.php');
	if(isset($POST->comment_content)) {
		$login = $_SESSION['kd_login'];
		$idu = queryo("select id from uzytkownicy where login='$login'")->id;
		query("insert into $tableName ( idu, idr, tresc, czas ) values ( '$idu', '$key', '$POSTs->comment_content', CURRENT_TIMESTAMP)");
	}

	$comments = query("select *, to_char(czas, 'DD.MM.YYYY HH24:MM:SS') as c from $tableName left join uzytkownicy on idu=id where idr=$key order by czas");
	echo "<table>\n";
	foreach($comments as $v)  {
		echo <<<HTML
<tr>
	<td>$v->c</td>
	<td>$v->login</td>
	<td>$v->tresc</td>
</tr>
HTML;
	}	
	echo "</table>\n";

	echo <<<HTML
<form method='post' action='$self'>
<textarea name='comment_content'></textarea>
<input type='submit' value='dodaj'/>
</form>	
HTML;
}
?>
